<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'MyJsp.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<style type="text/css">
strong {
	font-size: 15px;
}

pre {
	padding: 16px 0;
	line-height: 1.45;
	background-color: #f6f8fa;
	border-radius: 3px;
}
</style>

<script type="text/javascript" src="jQuery/jquery-3.3.1.js"></script>

<script type="text/javascript">

	$(document).ready(function() {

		//拿到bookid
		var bookid = $("#bookid").val();
		$.ajax({
			//通过bookid拿到这调数据
			url : "${pageContext.request.contextPath}/getwillsetServlet",
			data : {
				"bookid" : bookid
			},
			type : "get",
			dataType : "json",
			success : function(result) {
				//成功后把数据放到表单中
				alert(result.data.createDate);
				$("#bookid").val(result.data.id);
				$("#categoryid").val(result.data.categoryId);
				$("#title").val(result.data.title);
				$("#summary").val(result.data.summary);
				$("#uploadMan").val(result.data.uploadUser);
				$("#date2").val(result.data.createDate);
			},
			error : function() {
				//失败
				//跳转error界面。
				alert("失败");
				location.href = "${pageContext.request.contextPath}/error.jsp";
			}
		});
	});



	function add() {
		var xx = $("#form").serialize();
		$.ajax({
			url : "${pageContext.request.contextPath}/SetServelt",
			data : xx,
			type : "get",
			dataTyppe : "json",
			success : function(result) {

				$("#bookid").val("");
				$("#categoryid").val("");
				$("#title").val("");
				$("#summary").val("");
				$("#uploadMan").val("");
				$("#date2").val("");
				alert(result.msg);
				location.href = "${pageContext.request.contextPath}/EbookServlet";
			},
			error : function() {
				alert("我错了");
				location.href = "${pageContext.request.contextPath}/error.jsp";
			}
		})

	}
	;

	function Return() {
		location.href = "${pageContext.request.contextPath}/EbookServlet";
	}
</script>
</head>

<body>



	<div class="container">
		<div class="row clearfix">
			<div class="col-md-12 column">
				<h3 class="text-center">修改电子图书</h3>
				<form action="${pageContext.request.contextPath }/AddServlet"
					method="post" id="form">
					<input type="hidden" value="${param.bookid }" name="bookid"
						id="bookid"> <input type="hidden" value="" id="categoryid"
						name="categoryid">
					<table class="table table-bordered table-hover">
						<tr>
							<td>图书名称：</td>
							<td><input type="text" name="title" requierd="requierd"
								id="title"></td>
						</tr>
						<tr>
							<td>图书摘要:</td>
							<td><textarea style="height: 200px; width: 500px"
									name="summary" id="summary"></textarea></td>
						</tr>
						<tr>
							<td>上传人</td>
							<td><input type="text" name="uploadMan" requierd="requierd"
								id="uploadMan"></td>
						</tr>
						<tr>
							<td>上传时间</td>
							<td><input type="text" name="date" requierd="requierd"
								id="date2" value="2018-01-01"
								data-options="{'type':'YYYY-MM-DD','beginYear':2010,'endYear':2088}"
								style="width: 166px; height: 19px;"></td>
						</tr>
						<tr>
							<td></td>
							<td><input type="button" onclick="add();" value="提交"><input
								type="button" onclick="Return();" value="返回首页"></td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</div>


	<script src="js/jquery.min.js"></script>
	<script src="js/jquery.date.js"></script>
	<script>
	
		$.date('#date2');
	</script>




</body>
</html>
